package com.example.servicea.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.servicea.dao.PermissionMapper;
import com.example.servicea.entity.PermissionEntity;
import com.example.servicea.service.PermissionService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @Author generator.
 * @Date: 2017/10/26 10:58
 */
@Service("permissionServiceImpl")
public class PermissionServiceImpl implements PermissionService {
	@Autowired
	private PermissionMapper permissionMapper;

    @Override
    public boolean insert(PermissionEntity permission){
        return SqlHelper.retBool(permissionMapper.insert(permission));
    }
    @Override
    public List<PermissionEntity> selectList(PermissionEntity permission){
        EntityWrapper<PermissionEntity> query = new EntityWrapper<PermissionEntity>();
		return permissionMapper.selectList(query);
	}

    @Override
    public Page selectPage(PermissionEntity permission, String page, String limit){
        EntityWrapper<PermissionEntity> query = new EntityWrapper<PermissionEntity>();
        if(StringUtils.isNotBlank(permission.name)){
            query.like("name",permission.name);
        }
        List<PermissionEntity> list = permissionMapper.selectPage(
                new Page<PermissionEntity>(Integer.parseInt(page),Integer.parseInt(limit)),
                query);
        int total = permissionMapper.selectCount(query);
        Page PermissionEntityPage = new Page();
        return PermissionEntityPage;
	}
    @Override
    public int selectCount(PermissionEntity permission){
        EntityWrapper<PermissionEntity> query = new EntityWrapper<PermissionEntity>();
        return permissionMapper.selectCount(query);
	}

    @Override
    public PermissionEntity selectOne(PermissionEntity permission){
        return permissionMapper.selectOne(new PermissionEntity());
	}

    @Override
    public PermissionEntity selectById(String id){
        return permissionMapper.selectById(id);
	}

	@Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(PermissionEntity permission){
        return SqlHelper.retBool(permissionMapper.updateById(permission));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(String id){
        return SqlHelper.retBool(permissionMapper.deleteById(Integer.parseInt(id)));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatchIds(String ids){
        String[] s = ids.split(",");
        List<String> list = Arrays.asList(s);
        return SqlHelper.retBool(permissionMapper.deleteBatchIds(list));
	}
	
}
